import io
from dataclasses import dataclass

from flask import send_file
from injector import inject

from internal.service.tools_saervice import ToolsService
from pkg.resp.response import success_json


@inject
@dataclass
class BuiltinProviderManagerHanlder:
    tools_service: ToolsService

    def get_tool_provider_all(self):
        return success_json(self.tools_service.get_provider_tool())

    def get_tool_provider_find_name(self, provider_name: str, tool_name: str):
        return success_json(self.tools_service.get_tool_provider_find_name(provider_name, tool_name))

    def get_provider_icon(self, provider_name: str):
        icon, mimetype = self.tools_service.get_provider_icon(provider_name)
        return send_file(io.BytesIO(icon), mimetype)

    def get_category(self):
        return success_json(self.tools_service.get_category())
